﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;

namespace Atom.Utility
{
    public class ReadSqlXML
    {

        private static List<SqlEntity> list = null;

        public static string GetSql(string name)
        {
            //if (list == null)
            //{
            //List<SqlEntity> t = new List<SqlEntity>();
            string path = System.Windows.Forms.Application.StartupPath + "\\sql.xml";
            if (File.Exists(path))
            {
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(path);
                    foreach (DataRow row in ds.Tables["SQLXML"].Rows)
                    {
                        if (row["Name"].ToString().Equals(name))
                        {
                            //SqlEntity type = new SqlEntity();
                            //type.Name = row["Name"].ToString();
                            //type.SQL = row["SQL"].ToString();
                            //t.Add(type);
                            return row["SQL"].ToString();
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件失败！详细信息:" + e.Message);
                }
            }

            return string.Empty;
            // list = t;
            //}

            //return list;
        }
    }
}
